package com.vctgo.demo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vctgo.common.log.annotation.Log;
import com.vctgo.common.log.enums.BusinessType;
import com.vctgo.common.security.annotation.RequiresPermissions;
import com.vctgo.demo.domain.SysVoucher;
import com.vctgo.demo.service.ISysVoucherService;
import com.vctgo.common.core.web.controller.BaseController;
import com.vctgo.common.core.web.domain.AjaxResult;
import com.vctgo.common.core.utils.poi.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * 凭证字Controller
 *
 * @author vctgo
 * @date 2024-12-18
 */
@RestController
@RequestMapping("/voucher")
public class SysVoucherController extends BaseController
{
    @Autowired
    private ISysVoucherService sysVoucherService;

    /**
     * 查询凭证字列表
     */
    @RequiresPermissions("demo:voucher:list")
    @GetMapping("/list")
    public AjaxResult list(SysVoucher sysVoucher)
    {
        IPage<SysVoucher> list = sysVoucherService.selectSysVoucherPage(sysVoucher);
        return AjaxResult.success(list);
    }

    /**
     * 导出凭证字列表
     */
    @RequiresPermissions("demo:voucher:export")
    @Log(title = "凭证字", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysVoucher sysVoucher)
    {
        List<SysVoucher> list = sysVoucherService.selectSysVoucherList(sysVoucher);
        ExcelUtil<SysVoucher> util = new ExcelUtil<SysVoucher>(SysVoucher.class);
        util.exportExcel(response, list, "凭证字数据");
    }

    /**
     * 获取凭证字详细信息
     */
    @RequiresPermissions("demo:voucher:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysVoucherService.selectSysVoucherById(id));
    }

    /**
     * 新增凭证字
     */
    @RequiresPermissions("demo:voucher:add")
    @Log(title = "凭证字", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysVoucher sysVoucher)
    {
        return toAjax(sysVoucherService.insertSysVoucher(sysVoucher));
    }

    /**
     * 修改凭证字
     */
    @RequiresPermissions("demo:voucher:edit")
    @Log(title = "凭证字", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysVoucher sysVoucher)
    {
        return toAjax(sysVoucherService.updateSysVoucher(sysVoucher));
    }

    /**
     * 删除凭证字
     */
    @RequiresPermissions("demo:voucher:remove")
    @Log(title = "凭证字", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysVoucherService.deleteSysVoucherByIds(ids));
    }
}
